package njust.edu.web;

import njust.edu.dao.TradeDao;
import njust.edu.dao.*;
import njust.edu.dao.impl.*;
import njust.edu.entity.User;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

public class SalaryOpe {
    private Integer pageNo = 1;
    private List<UserSalary> userSalaryList = null;
    private Page<User> userPage = null;
    private List<User> userList = null;
    UserDao userdao = new UserDaoImpl();
    TradeDao tradeDao = new TradeDaoImpl();

    public Page<User> getUserPage() {
        return userPage;
    }

    public void setUserPage(Page<User> userPage) {
        this.userPage = userPage;
    }



    public List<UserSalary> getUserSalaryList() {
        return userSalaryList;
    }

    public void setUserSalaryList(List<UserSalary> userSalaryList) {
        this.userSalaryList = userSalaryList;
    }

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public SalaryOpe(Integer pageNo, Date dateFrom, Date dateTo,Date today) {
        userSalaryList = new ArrayList<UserSalary>();
        UserSalary userSalary = null;
        this.pageNo = pageNo;
        userPage = userdao.getPage(pageNo);

        //System.out.println(dateFrom+" "+dateTo);

        userList = userPage.getList();
        for (User user : userList) {

            if (user.getType()!=3)
                continue;

            userSalary = new UserSalary();

            //System.out.println(user.getId());

            userSalary.setId(user.getId());
            userSalary.setName(user.getName());
            Double monthGet = tradeDao.getUserMonthSalary(user.getId(),
                    dateFrom, dateTo);
            Double dayGet=tradeDao.getUserDaySalary(user.getId(),today);

            //System.out.println(monthGet);

            if(monthGet == null)
            {
                userSalary.setMonthGet(0d);
            }else{
                userSalary.setMonthGet(monthGet);
            }

            if(dayGet == null)
            {
                userSalary.setDayGet(0d);
            }else{
                userSalary.setDayGet(dayGet);
            }


            userSalaryList.add(userSalary);
        }
    }
}
